package com.mall.b2c.domain.order;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlTransient;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mall.b2c.domain.goods.GoodsDomain;
import com.mall.b2c.domain.store.StoreDomain;
import com.mall.common.domain.BaseEntity;

/**
 * 购物车货品项
 */
@Entity
@Table(name = "b2c_cart_item")
public class CartItemDomain extends BaseEntity {
	
	private static final long serialVersionUID = -3123400196324597451L;
	@JsonIgnore private GoodsDomain goods;// 商品类
	@JsonIgnore private CartDomain cart;//购物车
//	@JsonIgnore private StoreDomain store; //门店

	private Integer num;// 购买数量

	public Integer getNum() {
		return num;
	}

	public void setNum(Integer num) {
		this.num = num;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@XmlTransient
	public CartDomain getCart() {
		return cart;
	}

	public void setCart(CartDomain cart) {
		this.cart = cart;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@XmlTransient
	public GoodsDomain getGoods() {
		return goods;
	}

	public void setGoods(GoodsDomain goods) {
		this.goods = goods;
	}

/*	@ManyToOne(fetch = FetchType.LAZY)
	public StoreDomain getStore() {
		return store;
	}

	public void setStore(StoreDomain store) {
		this.store = store;
	}*/

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof CartItemDomain){
			CartItemDomain item = (CartItemDomain) obj;
			if(getGoods().getId().equals(item.getGoods().getId())){
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		if(goods != null){
			return goods.getId().hashCode();
		}
		return super.hashCode();
	}
	
	
}
